﻿Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Public Class CircleLable
    Private fontFamily As New FontFamily(New GenericFontFamilies)
    Public LabelFont As New Font(fontFamily, 10, FontStyle.Regular, GraphicsUnit.Pixel)
    Public LabelColor As Color = Color.Black

    Private m_Visible As Boolean = True
    Property Visible() As Boolean
        Get
            Return m_Visible
        End Get
        Set(ByVal value As Boolean)
            m_Visible = value
        End Set
    End Property


    Public Sub Draw(ByVal grap As Graphics, ByVal m_Interval As Single, ByVal m_Count As Integer, ByVal BackColor As Color, ByVal Location As PointF, ByVal m_Check As Boolean)
        '以下根据每一条等值线的情况进行绘制等值线的标注
        If m_Visible Then '如果等值线的标注可见，就绘制等值线的标注
            For i As Integer = 0 To m_Count - 1
                Dim LabelBrush As New SolidBrush(LabelColor)

                Dim LabelFormat As New StringFormat
                Dim TextHeight As Double '字的高度
                LabelFormat.Alignment = StringAlignment.Center   '文字左对齐
                Dim myMatrix As New Matrix()
                Dim graphicsContainer As GraphicsContainer '嵌套的 Graphics 容器 
                graphicsContainer = grap.BeginContainer() '开始嵌套的 Graphics 容器
                myMatrix.Translate((i + 1) * m_Interval, 0) '平移到两点之间
                TextHeight = grap.MeasureString(CStr(i), LabelFont).Height * PannelSetting.gScale
                myMatrix.Translate(Location.X, Location.Y + TextHeight / 2)
                myMatrix.Scale(PannelSetting.gScale, PannelSetting.gScale) '将字体按比例回放
                myMatrix.Multiply(New Matrix(1, 0, 0, -1, 0, 0)) '反转
                grap.Transform = myMatrix
                Try
                    Dim Mypath As New GraphicsPath()
                    Dim BackBrush As New SolidBrush(BackColor)
                    If m_Check Then
                        '风速图
                        Mypath.AddString((i + 1) * m_Interval, LabelFont.FontFamily, LabelFont.Style, LabelFont.Size, New PointF(0, 0), LabelFormat)
                        Dim rectf As RectangleF = Mypath.GetBounds()
                        Dim region As New Region(rectf) '绘图的标注的路径区域 
                        grap.FillRegion(BackBrush, region)
                        grap.DrawString((i + 1) * m_Interval, LabelFont, LabelBrush, 0, 0, LabelFormat)
                    Else
                        '风频图
                        Mypath.AddString((i + 1) * m_Interval & "%", LabelFont.FontFamily, LabelFont.Style, LabelFont.Size, New PointF(0, 0), LabelFormat)
                        Dim rectf As RectangleF = Mypath.GetBounds()
                        Dim region As New Region(rectf) '绘图的标注的路径区域 
                        grap.FillRegion(BackBrush, region)
                        grap.DrawString((i + 1) * m_Interval & "%", LabelFont, LabelBrush, 0, 0, LabelFormat)
                    End If
                Catch
                End Try
                grap.EndContainer(graphicsContainer) '退出绘图容器
            Next
        End If
    End Sub
End Class
